var e = require("../../../@babel/runtime/helpers/interopRequireDefault").default, a = require("../../../config/CT_share_index/index.js"), t = e(require("../../../utils/Tips")), n = e(require("../../../api/api_CTShare")), o = getApp(), i = o.eventBus;

Component({
    data: {
        shareID: "",
        currentIndex: 0,
        CTImageBaseUrl: a.imageBaseUrl.CT_share_index,
        gotoUrl: "",
        options: {}
    },
    attached: function() {
        var e = this;
        this.setData({
            options: {}
        }), this.getOptions().then(function() {
            return e.getShareInfo();
        }).then(function() {
            e.creat_gotoUrl();
        });
    },
    detached: function() {
        this.CTShare_newUserOptions && this.CTShare_newUserOptions.off();
    },
    methods: {
        gotoRule: function() {
            wx.navigateTo({
                url: "/pages/CT_share_newUser_rule/index?adtag=" + o.globalData.aucChannel
            });
        },
        getOptions: function() {
            var e = this;
            return new Promise(function(a, t) {
                e.CTShare_newUserOptions = i.on("CTShare_newUserOptions", function(n) {
                    e.setData({
                        options: n
                    }), n.sid && n.channel && (o.globalData.aucChannel = n.channel), n.scene || n.sid || t(), 
                    a();
                });
            });
        },
        getShareInfo: function() {
            var e = this;
            return new Promise(function(a, i) {
                wx.showLoading({
                    title: "加载中"
                });
                var r = {
                    scene: e.data.options.scene ? e.data.options.scene : "",
                    sid: e.data.options.sid ? e.data.options.sid : ""
                };
                console.log("获取shareId接口传参", r), n.default.getShareInfo(r).then(function(n) {
                    console.log("获取分享信息shareId成功", n), wx.hideLoading();
                    var i = n.code, r = n.result;
                    n.msg;
                    "0" === i ? (!e.data.options.channel && r && r.channel && (o.globalData.aucChannel = r.channel), 
                    r && r.shareID && r.idType ? (e.setData({
                        shareID: r.shareID,
                        idType: r.idType
                    }), a()) : (t.default.toast("无shareID，邀请人将无法获得奖励"), a())) : (t.default.toast("无shareID，邀请人将无法获得奖励"), 
                    a());
                }).catch(function(e) {
                    console.log("获取分享信息shareId失败", e), wx.hideLoading(), a(e);
                });
            });
        },
        creat_gotoUrl: function() {
            var e = this;
            return new Promise(function(t, n) {
                var i, r = "";
                e.data.shareID && e.data.idType && (r = "&ShareID=".concat(e.data.shareID, "&IdType=").concat(e.data.idType));
                var s = "&channel=" + o.globalData.aucChannel + "&ADTAG=" + o.globalData.aucChannel;
                i = a.baseKCardOrderUrl + "?productType=k104&showRent=1&policyId=T0050" + s + r, 
                console.log("下单页地址", i), e.setData({
                    gotoUrl: i
                });
            });
        },
        apply: function() {
            var e = this;
            this.data.shareID && this.data.idType && this.data.gotoUrl ? e.toWebView() : wx.showModal({
                content: "无Shareid参数，请刷新当前页面后重试，或者通过活动页重新分享后下单",
                confirmText: "刷新",
                success: function(a) {
                    var t = this;
                    a.confirm && e.getShareInfo().then(function() {
                        return e.creat_gotoUrl();
                    }).then(function() {
                        t.toWebView();
                    });
                }
            });
        },
        toWebView: function() {
            wx.navigateTo({
                url: "/pages/webview/index"
            }), i.emit("toWebviewPage", {
                url: this.data.gotoUrl
            });
        }
    }
});